package com.xcw.handler;

import cn.hutool.core.util.StrUtil;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.session.WxSessionManager;
import me.chanjar.weixin.mp.api.WxMpMessageHandler;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Map;

/**
 * @Author bhx
 * @Date 2022/8/27 23:07
 * @Description TODO
 */
public class TextHandler implements WxMpMessageHandler {

    @Autowired
    LoginHandler loginHandler;

    @Override
    public WxMpXmlOutMessage handle(WxMpXmlMessage wxMpXmlMessage, Map<String, Object> map, WxMpService wxMpService, WxSessionManager wxSessionManager) throws WxErrorException {
        String openid = wxMpXmlMessage.getOpenId();
        String context = wxMpXmlMessage.getContent();
        if (StrUtil.isNotBlank(context)) {
            context = context.toUpperCase().trim();

            if (context.indexOf("DY") == 0){

                String res = loginHandler.hanlde(openid, context, wxMpService);
            }
        }
        return null;
    }
}
